// Initialize butotn with users's prefered color
var gh = (function() {

  var xiaqi;

  var user_info_div;

  return {
    onload: function () {
        xia();
  user_info_div = document.querySelector('#user_info');
   }
  };



function xia() {
  qixia('GET', 'http://localhost:80/getPoem',
      false, qi);
}
function qixia(method, url, interactive, callback) {
  var xhr = new XMLHttpRequest();
  xhr.open(method, url);
xhr.onload = requestComplete;
  xhr.send();
function requestComplete() {
  // console.log('requestComplete', this.status, this.response);
  if ( ( this.status < 200 || this.status >=300 ) ) {

  } else {
    callback(null, this.status, this.response);
  }
}
}
function qi(error, status, response) {
  if (!error && status == 200) {
        var poem = JSON.parse(response);
        var elem = user_info_div;
        var nameElem = document.createElement('div');
        nameElem.innerHTML = "<p> " + poem.Content+"。  "+ poem.Dynasty +
            "  "+poem.AuthorName+ "</p>";
        elem.appendChild(nameElem);

  }
}



})();




window.onload = gh.onload;